﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace InterfaceFiles
{
  public class TextInterfaceHeader : BaseInterfaceHeader, IInterfaceHeader
  {
    public TextInterfaceHeader(IInterfaceReader reader, IInterfaceWriter writer)
      : base(reader, writer)
    {
    }
    #region IInterfaceHeader Implementation

    public override void Write()
    {
      throw new NotImplementedException();
    }

    public override void Write(IInterfaceHeader header)
    {
      Console.WriteLine(string.Format("writer = null: {0}, header.Titles[0] = null: {1}",
        writer == null, header.Titles[0] == null));
      writer.WriteString(header.Titles[0]);
      writer.FlushRecord();

      writer.WriteString(header.Titles[1]);
      writer.FlushRecord();
      
      writer.WriteInt(((JulianDate)header.StartTime).Raw);
      writer.WriteDouble(header.StartTime.TimeOfDay.TotalSeconds);
      writer.FlushRecord();
      
      writer.WriteString(header.Titles[2]);
      writer.FlushRecord();

      writer.WriteString(header.Titles[3]);
      writer.FlushRecord();

      writer.WriteString(header.SourceBlock.PadRight(20));
      writer.WriteInt(header.NumNodes);
      writer.WriteInt(header.NumPollutants);
      writer.WriteDouble(header.Area_sqft);
      writer.WriteInt(1);
      writer.FlushRecord();

      foreach (string node in header.Nodes)
      {
        writer.WriteString(node.PadRight(16));
      }
      writer.FlushRecord();

      writer.WriteDouble(header.FlowMultiplier);
      writer.FlushRecord();
    }
    #endregion
  }
}
